﻿@model ShoppingCartModel
@using Nop.Core.Domain.Orders
@using Nop.Web.Models.Checkout
@using Nop.Web.Models.ShoppingCart;
@{
    Layout = "~/Views/Shared/_Layout.cshtml";
    //title
    Html.AddTitleParts(T("PageTitle.ShoppingCart").Text);
    ViewBag.IsCart = true;
}
<div class="shopping-cart row">
    <div class="col-sm-12">
        <h1 class="page-title"><span class="title-image"></span> @T("ShoppingCart")</h1>
        @Html.Action("RenderMessages", "Common", new { area = "" })
        @if (Model.AllItems.Count > 0)
        {
            <div class="row">
                <div class="col-xxs-12 col-xs-12 col-sm-12 col-md-12 col-lg-12">
                    <div class="cart-order-summary">
                        @Html.Partial("OrderSummary", Model)
                    </div>
                </div>
                <div class="col-xs-12 col-sm-8 col-md-8 col-lg-8">
                    <div class="cart-order-total">
                        @Html.Action("OrderTotals", "ShoppingCart", new { isEditable = Model.IsEditable })
                    </div>
                    <div class="clear"></div>

                    <div class="row">
                        @using (Html.BeginRouteForm("ShoppingCart", FormMethod.Post, new { enctype = "multipart/form-data", id = "checkoutId" }))
                        {
                            if (Model.IsEditable)
                            {
                                <div class="checkbox col-xs-12">
                                    <label>
                                        <input type="checkbox" id="gitMessageCheck"> @T("Checkout.GiftMessage")
                                    </label>
                                </div>
                                @Html.Partial("_CheckoutAttributes", Model.CheckoutAttributes, new ViewDataDictionary())
                            }
                            <div class="clear"></div>
                            <div class="checkout-buttons">
                                <div class="col-xs-12 col-md-6">
                                    <input type="submit" id="checkout" name="checkout" value="@T("Checkout.Button")" class="btn btn-danger form-control" />
                                </div>
                                <div class=" col-xs-12 col-md-6">
                                    @Html.ActionLink("Clear Shopping Cart", "RemoveAllProductsFromCart", "ShoppingCart", new { shoppingCartTypeId = 1 }, new { @class = "btn btn-normal form-control" })
                                </div>
                                <div class="clear"></div>
                                <script type="text/javascript">

                                    $(function() {
                                        opera.init();
                                    });
                                    (function() {
                                        var opera = {
                                            init: function() {
                                                opera.gitmessageTaggleEvent();
                                                opera.checkoutEvent();
                                                opera.isHideOrShow();
                                            },
                                            isHideOrShow:function() {
                                                var iptObjs= $('#msgId textarea');
                                                if (iptObjs.length > 0&&$(iptObjs[0]).text().length>0) {
                                                    $("#gitMessageCheck").click();
                                                } else {
                                                    $('#msgId').hide();
                                                }
                                            },
                                            gitmessageTaggleEvent: function() {
                                                $("#gitMessageCheck").click(function() {
                                                    $('#gitMessageCheck').is(':checked') ? $('#msgId').show() : $('#msgId').hide();
                                                });
                                            },
                                            checkoutEvent: function() {
                                                $('#checkout').click(function() {
                                                    if ($('#gitMessageCheck').is(':checked')) {
                                                        if (!opera.validateMsgData()) {
                                                            alert('Field cannot be empty');
                                                            return false;
                                                        }
                                                    } else {
                                                        $.each($('.gitMessage'), function() {
                                                            $(this).val('');
                                                        });
                                                    };
                                                    return true;
                                                });
                                            },
                                            validateMsgData: function() {
                                                var flag = true;
                                                $.each($('#msgId input'), function() {
                                                    if (opera.isNullOrEmpty($(this).val())) {
                                                        flag = false;
                                                        return false;
                                                    }
                                                    return true;
                                                });
                                                return flag;
                                            },
                                            isNullOrEmpty: function(value) {
                                                return value == null || value.length <= 0;
                                            }
                                        };
                                        window.opera = opera;
                                    })();

                                    //暂时 之后要修改成为可配置
                                    function shipTimeShow() {
                                        var hasShipTime = @Model.CheckoutAttributes.Any(x => x.Name == "ShipTime");
                                        if (!hasShipTime)
                                            return;
                                        else {
                                            @*var id = "checkout_attribute_" + @Model.CheckoutAttributes.First(x => x.Name == "ShipTime").Id;
                                    $("#"+id).hide();*@
                                        }
                                    }
                                </script>

                            </div>
                        }
                    </div>

                </div>
                <div class="col-xs-12 col-sm-4">
                    <div class="cart-delivery">
                        <div class="image"></div>
                    </div>
                </div>
            </div>

        }
        else
        {
            <div class="empty-cart">
                <p>@T("ShoppingCart.CartIsEmpty")</p>
                <div class="shop-now-button">
                    <a href="@Url.Content("~/Commerce")" class="button-red btn btn-danger">Shop Now</a>
                </div>
            </div>

        }
        @Html.Hidden("cart-remove-item", Url.Action("RemoveItemFromCart", "ShoppingCart"))
        @Html.Hidden("cart-edit-item", Url.Action("EditItemInCart", "ShoppingCart"))
    </div>
</div>

@section FluidBottom
{
    @Html.Action("CrossSellProducts", "Catalog")
    <div class="clear"></div>
    @if (Model.AllItems.Count == 0)
    {
        @Html.Action("HomepageProducts", "Catalog", new { area = "Commerce" })
        <div class="clear"></div>
    }
}

@section Bottom
{

    @Html.Action("RecentlyViewedProductsBlock", "Catalog", new { area = "Commerce" })
}
